package com.shangxia.basic.common.demo;

import lombok.extern.slf4j.Slf4j;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;

/**
 * @ProjectName: rachel
 * @ClassName: UrlDemo
 * @Time: 2020/6/10
 * @Author: zy9524
 * @Description:
 * @Experience:
 */

@Slf4j
public class UrlDemo {
    public static void main(String[] args) throws IOException {

        URL url = new URL("http://www.baidu.com");

        /* 字节流 */
        InputStream is = url.openStream();

        /* 字符流 */
        InputStreamReader isr = new InputStreamReader(is, "utf-8");

        /* 提供缓存功能 */
        BufferedReader br = new BufferedReader(isr);
        System.out.println("start");
        String line;
        while ((line = br.readLine()) != null) {
            System.out.println(line);
        }
        System.out.println("end");
        br.close();
    }
}
